using System;
using System.Text;
using System.Runtime.InteropServices;
using System.Windows.Forms;
using System.Drawing.Imaging;
using System.Drawing;
using System.Diagnostics ;
using System.Xml.Serialization;
namespace AppliedRecognition.Speech.TaskSupport {
	
	/// <summary>
	/// Provides details about a Window returned by the 
	/// enumeration
	/// </summary>
	/// 
	[Serializable]
	public sealed class SerialiedWindowItem {
	
		public  SerialiedWindowItem()
		{
		}

		public SerialiedWindowItem(WindowItem wi, bool capScreen)
		{
			init(wi,capScreen);
		}

		public SerialiedWindowItem(WindowItem wi)
		{
			init(wi,false);
		}
		
		private void init(WindowItem wi, bool capScreen)
		{
			this.OwnerHandle = wi.OwnerHandle.ToInt32().ToString("x") ;
			this.ClassName = wi.ClassName ;
			this.ExtendedWindowStyle = wi.ExtendedWindowStyle ;
			this.Handle = wi.Handle.ToInt32().ToString("x");
			
			this.Icon = wi.Icon ;
			this.Iconic = wi.Iconic ;
			this.IsExAppWindow = wi.IsExAppWindow ;
			this.IsExToolWindow = wi.IsExToolWindow ;
			this.IsModalDialog = wi.IsModalDialog;
			this.IsPopUp=wi.IsPopUp;
			this.IsTopMost=wi.IsTopMost;
		//	this.Location =wi.Location;
			this.Maximised=wi.Maximised;
			this.Rect=wi.Rect;
//			this.Size = wi.Size;
			this.TaskVisible = wi.TaskVisible;
			this.Text=wi.Text;
			this.Visible = wi.Visible;
			
			string wsString = wi.WindowStyle.ToString();
			
			try
			{
				uint wsInt = uint.Parse(wsString);
				wsString = wi.WindowStyle.ToString("x");
			}
			catch (FormatException)
			{
			}
			catch (OverflowException)
			{
				wsString = wi.WindowStyle.ToString("x");
			}

			this.WindowStyle = wsString;
			this.IsExControlParent = wi.IsExControlParent ;
			this.IsOwnerExToolWindow = wi.IsOwnerExToolWindow ;
			this.IsEqualToParent = (wi.Handle == wi.OwnerHandle);
			this.NotTaskVisibleReason = wi.NotTaskVisibleReason;

			if (capScreen)
			{
				this.ScreenShot=wi.ScreenShot;
			}
			

		}

		private bool _TaskVisible;
		public bool TaskVisible 
		{
			get { return _TaskVisible;}
			set { _TaskVisible = value; }
		}
		private string notTaskVisibleReason;
		public string NotTaskVisibleReason 
		{
			get { return this.notTaskVisibleReason; } set { this.notTaskVisibleReason = value;}
		}


		private string _ChildHandle;
		public string OwnerHandle {
			get { return _ChildHandle;}
			set { _ChildHandle = value; }
		}
		private string _Handle;
		public string Handle {
			get { return _Handle;}
			set { _Handle = value; }
		}



		public bool IsOwnerEqualToHandle {
			get { return (OwnerHandle == Handle )? true:false;}
		}

		private string _Text;
		public string Text {
			get { return _Text;}
			set { _Text = value; }
		}
	
		private string _ClassName;
		public string ClassName {
			get { return _ClassName;}
			set { _ClassName = value; }
		}
	
		private bool _Visible;
		public bool Visible {
			get { return _Visible;}
			set { _Visible = value; }
		}
		
		private bool _Iconic;
		public bool Iconic {
			get { return _Iconic;}
			set { _Iconic = value; }
		}
		
		private bool _Maximised;
		public bool Maximised {
			get { return _Maximised;}
			set { _Maximised = value; }
		}
		
		private Rectangle _Rect;
		public Rectangle Rect {
			get { return _Rect;}
			set { _Rect = value; }
		}
		
//		private Point _Location;
//		public Point Location {
//			get { return _Location;}
//			set { _Location = value; }
//		}
		
//		private Size _Size;
//		public Size Size {
//			get { return _Size;}
//			set { _Size = value; }
//		}
		
		private string _WindowStyle;
		public string WindowStyle { // WindowStyleFlags
			get { return _WindowStyle;}
			set { _WindowStyle = value; }
		}
		
		private WS_EX _ExtendedWindowStyle;
		public WS_EX ExtendedWindowStyle {
			get { return _ExtendedWindowStyle;}
			set { _ExtendedWindowStyle = value; }
		}
		
		private bool _IsPopUp;
		public bool IsPopUp {
			get { return _IsPopUp;}
			set { _IsPopUp = value; }
		}
		
		private bool _IsExToolWindow;
		public bool IsExToolWindow {
			get { return _IsExToolWindow;}
			set { _IsExToolWindow = value; }
		}
		
		private bool _IsExAppWindow ;
		public bool IsExAppWindow  {
			get { return _IsExAppWindow ;}
			set { _IsExAppWindow  = value; }
		}
		
		private bool _IsExControlParent;
		public bool IsExControlParent {
			get { return _IsExControlParent;}
			set { _IsExControlParent = value;}
		}
		private bool _IsModalDialog;
		public bool IsModalDialog {
			get { return _IsModalDialog;}
			set { _IsModalDialog = value; }
		}
		
		private bool _IsTopMost;
		public bool IsTopMost {
			get { return _IsTopMost;}
			set { _IsTopMost = value; }
		}
		
		[XmlIgnore] private Icon _Icon;
		[XmlIgnore] public Icon Icon {
			get { return _Icon;}
			set { _Icon = value; }
		}

		private Image _ScreenShot;
		[XmlIgnore] public Image ScreenShot {
			get { return _ScreenShot;}
			set { _ScreenShot = value; }
		}
		


		private bool _IsOwnerExToolWindow;
		public bool IsOwnerExToolWindow {
			get { return _IsOwnerExToolWindow;}
			set { _IsOwnerExToolWindow = value; }
		}
		
		private bool _IsEqualToParent;
		public bool IsEqualToParent {
			get { return _IsEqualToParent;}
			set { _IsEqualToParent = value; }
		}

		

	}

}
